package com.lebang.controller.sys;

import com.lebang.common.Login;
import com.lebang.entity.sys.SysResource;
import com.lebang.service.sys.SysResourceService;
import com.lebangweb.response.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * 描述：任务收退款管理控制层
 *
 * @author HWQ
 * @date Thu Apr 25 15:40:21 CST 2019
 */
@Login
@Controller
@RequestMapping("/resource")

public class SysResourceController {

    @Autowired
    private SysResourceService sysResourceService;

    @Login
    @GetMapping("/list")
    public String list() {
        return "/resource/tbresource-list";
    }

    /**
     * 新增修改保存
     **/
    @Login
    @PostMapping("/edit")
    @ResponseBody
    public JsonData edit(SysResource po) {
        if (po.getId() == null) {
            return sysResourceService.insert(po);
        } else {
            return sysResourceService.update(po);
        }
    }

    /**
     * 新增修改跳转
     **/
    @GetMapping("/edit")
    @Login
    public String edit(@RequestParam(name = "id", required = false) Long id,
                       Model model) {
        if (!"".equals(id) && null != id) {
            model.addAttribute("item", sysResourceService.selectByPrimaryKey(id));
        } else {
            SysResource sysResource = new SysResource();
            sysResource.setCategory("MenuItem");
            model.addAttribute("item", sysResource);
        }
        model.addAttribute("parentlist", sysResourceService.findAllparent());
        return "/resource/tbresource-edit";
    }
}